package cn.meike.server;

import java.util.Random;
import java.util.Vector;

public class Poker 
{

	public static final int POKER_TOTAL_CARDS_NUM = 52;
	public static final int POKER_ONE_TYPE_CARDS_NUM = 13;
	public static final int POKER_CARDS_TYPE_SPADKS = 0;
	public static final int POKER_CARDS_TYPE_HEARTS = 13;
	public static final int POKER_CARDS_TYPE_CLUBS = 26;
	public static final int POKER_CARDS_TYPE_DIAMONDS = 39;
	
	private Vector<Card> m_cards = null;
    private Random m_random = null;
    
    public Poker()
    {
        _init();
    }
    
    private void _init()
    {
        m_cards = new Vector<Card>(POKER_TOTAL_CARDS_NUM);
        for(int i = 0 ; i <POKER_TOTAL_CARDS_NUM ; ++i )
        {
            m_cards.add(_createCard(i));
        }
    }
    
    public void shuffle()
    {
        if(null == m_cards || m_cards.size() != POKER_TOTAL_CARDS_NUM)
        {
            return ;
        }
        
        if(null == m_random)
        {
            m_random = new Random();
        }
        m_random.setSeed(System.currentTimeMillis());
        
        int _indexRandom = 0; 
        for(int i = 0 ; i <POKER_TOTAL_CARDS_NUM ; ++i)
        {
             _indexRandom = m_random.nextInt(POKER_TOTAL_CARDS_NUM);
             m_cards.add(0,m_cards.remove(_indexRandom));
        }
    }
    
    private Card _createCard(int n)
    {
        Card _ret = new Card();
        //
        if( n>=POKER_CARDS_TYPE_SPADKS && n<POKER_CARDS_TYPE_HEARTS)
        {
            _ret.type = POKER_CARDS_TYPE_SPADKS;
            _ret.num = n;
        }
        else if(n>=POKER_CARDS_TYPE_HEARTS && n<POKER_CARDS_TYPE_CLUBS)
        {
            _ret.type = POKER_CARDS_TYPE_HEARTS;
            _ret.num = n - POKER_CARDS_TYPE_HEARTS;
        }
        else if(n>=POKER_CARDS_TYPE_CLUBS && n<POKER_CARDS_TYPE_DIAMONDS)
        {
            _ret.type = POKER_CARDS_TYPE_CLUBS;
            _ret.num = n - POKER_CARDS_TYPE_CLUBS;
        }
        else if(n>=POKER_CARDS_TYPE_DIAMONDS && n<POKER_TOTAL_CARDS_NUM)
        {
            _ret.type = POKER_CARDS_TYPE_DIAMONDS;
            _ret.num = n - POKER_CARDS_TYPE_DIAMONDS;
        }
        
        return _ret;
    }
    
    public String toString()
    {
        return null;
    }
}
